package com.cn.sl.server.api.system.department.util

import com.cn.sl.server.api.system.department.model.entity.DepartmentEntity
import com.cn.sl.server.util.findChildren

fun updateChildrenNamePath(entity: DepartmentEntity, entities: List<DepartmentEntity>) {
    val children = findChildren(entity, entities, { it.id }, { it.parentId })
    if (children.isNotEmpty()) {
        children.forEach { child ->
            child.namePath = entity.namePath.toMutableList().apply {
                add(child.name)
            }
            updateChildrenNamePath(child, entities)
        }
    }
}